<%--
 *  File:    ItemCategoryTree.jsp
 *  @Author: Langerwang 
 *  Date:    2002/01/14
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.ItemCategoryTree");    
%>

<% //--------------------------------------  variant and initialization --%>
<%
  	//String strModuleName = "PCM";    
  	//String privilegeCode = "10206";
  	  	String privilegeCode = "All";
        String strModuleName = "COM";
%>

 
<%
HashMap userInfo = (HashMap)session.getAttribute("userinfo");  
Integer nCurOrgId = (Integer)userInfo.get("orgid");
%>


<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
 
<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="itemcategorytree"/>

<% //--------------------------------------  output variant from pageflow --%>
<%
  	Vector categories = (Vector)pageContext.getAttribute("categorytree");
      
  	if(categories == null)
    	categories = new Vector();

  	cat.debug("The categories is :" + categories.size() + categories);
  	OvalTree initTree = new OvalTree(categories,"categoryid","parentcategoryid","grade");
  	initTree.setRecursiveLimit(2000);
  	Vector categoryTree = (Vector)initTree.getTreeVector(new Integer(-1000),1);  
  	  	String param="";
  	if(request.getParameter("param")!=null) 
  	    param = (String)request.getParameter("param"); 
  	cat.debug("The tree's size is :" + categoryTree.size());
  	cat.debug("The tree is :" + categoryTree);
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<link rel="stylesheet" href="../../css/cn/widget.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../../css/menu.js"></SCRIPT>
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="../../js/opal2/mootools.js"></script>
<script language="JavaScript" src="../../js/opal2/opal2.js"></script>
<script language="JavaScript">

parent.rightFrame.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
function page_view(id,grade,isbottom,parentid,cid)
{
  document.itemcategoryform.categoryid.value = id;
  document.itemcategoryform.grade.value = grade; 
  document.itemcategoryform.isbottom.value = isbottom;  
  document.itemcategoryform.parentcategoryid.value = parentid;  
  document.itemcategoryform.cid.value = cid;

  var catorgid = null;
  if(document.itemcategoryform.categoryorgid != null)
    catorgid = document.itemcategoryform.categoryorgid.value;
  
  var sellerid="";
  if(!isEmpty(document.itemcategoryform.sellerid.value) )
    sellerid = document.itemcategoryform.sellerid.value;
  
  var ispoitem="";
  if(!isEmpty(document.itemcategoryform.ispoitem.value) )
    ispoitem = document.itemcategoryform.ispoitem.value;

  var itemcode="";
  if(!isEmpty(document.itemcategoryform.itemcode.value) )
    itemcode = document.itemcategoryform.itemcode.value;    
    
  var deptid="";
  if(!isEmpty(document.itemcategoryform.deptid.value) )
    deptid = document.itemcategoryform.deptid.value;    
    
  if(id == null || id.length == 0 || id == "")
     return;

var strorgid=document.itemcategoryform.orgid.value;
  var transferorgid=document.itemcategoryform.transferorgid.value;  
  var link = "ItemSelectForPO1.jsp?<%= OvalTools.randomURL() %>&param=<%=JspHelper.filterNull( param)%>&languagecode=" + "<%= strLanguageCode %>" + "&orgid="+strorgid + "&categoryorgid=" + catorgid+"&sellerid="+sellerid+"&ispoitem="+ispoitem+"&partitemcode="+itemcode+"&deptid="+deptid;
  if(id != -1)
    link = link + "&categoryid=" + id + "&selectopt=categoryall";
  else
    link = link + "&selectopt=categoryall";
  var strbuyerid=document.itemcategoryform.buyerid.value ;
  if(!isEmpty(strbuyerid))
    link = link + "&buyerid="+strbuyerid;  

  if(!isEmpty(transferorgid))
    link = link + "&transferorgid="+transferorgid;      
  
  parent.rightFrame.location.href = link; 
  
}
function page_sum(flag)
{
  var catorgid = null;
  if(document.itemcategoryform.categoryorgid != null)
    catorgid = document.itemcategoryform.categoryorgid.value;
    
  var sellerid="";
  if(!isEmpty(document.itemcategoryform.sellerid.value) )
    sellerid = document.itemcategoryform.sellerid.value;  
    
  var ispoitem="";
  if(!isEmpty(document.itemcategoryform.ispoitem.value) )
   ispoitem = document.itemcategoryform.ispoitem.value;
  
  var itemcode="";
  if(!isEmpty(document.itemcategoryform.itemcode.value) )
   itemcode = document.itemcategoryform.itemcode.value;   
   
   var deptid="";
  if(!isEmpty(document.itemcategoryform.deptid.value) )
   deptid = document.itemcategoryform.deptid.value;   
   
   var transferorgid="";
  if(!isEmpty(document.itemcategoryform.transferorgid.value) )
    transferorgid = document.itemcategoryform.transferorgid.value;

  var strorgid=document.itemcategoryform.orgid.value;

  var link = "ItemSelectForPO1.jsp?<%= OvalTools.randomURL() %>&param=<%=JspHelper.filterNull( param)%>&selectopt=" + flag + "&orgid="+strorgid+"&categoryorgid=" + catorgid + "&languagecode=<%= strLanguageCode %>&sellerid="+sellerid+"&ispoitem="+ispoitem+"&partitemcode="+itemcode+"&deptid="+deptid;

  var strbuyerid=document.itemcategoryform.buyerid.value ;
  if(strbuyerid!=null)
    link = link + "&buyerid="+strbuyerid ;
  if(!isEmpty(transferorgid))
    link = link + "&transferorgid="+transferorgid ;

    
  parent.rightFrame.location.href = link;  
  setallrediotofalse();  
}

function setallrediotofalse()
{
    with(document.itemcategoryform)
    {
        if(typeof(categoryids.length)=="undefined")
            categoryids.checked=false;
        else
        {
            for(var i=0;i<categoryids.length;i++)
            {
                if(categoryids[i].checked)
                {
                    categoryids[i].checked=false;
                    break;
                }
            }
        }
    }
}

function page_ajaxgo(){
        $('treeView1').selectedNode.clearChildren();
    	}
    	
			window.addEvent('domready', function() {	
				opal.widget.TreeView.image.path = '../../images/';	
				var treeView = new opal.widget.TreeView({
					id: 'treeView1'
				});
				
				treeView.ajaxHelper.pageName = 'itemcategorytree';
				treeView.ajaxHelper.actionName = 'gobyajax';	
				treeView.ajaxHelper.staticParams = '';	
				treeView.ajaxHelper.dynamicParams = '';	
				treeView.DataPackName = 'categorytree';								
				treeView.idName = 'categoryid';
				treeView.textName = 'categoryname';
				treeView.isBottomName = 'isbottom';
				treeView.onRequestData = function(Node, ajaxHelper){
				  if ($defined(Node.grade)){
                   ajaxHelper.dynamicParams = 'parentcategoryid=' + Node.id;					  
				  }else{
				    ajaxHelper.dynamicParams = 'grade=1';					  
				  } 
				};				
				treeView.onNodeGetData = function(Node, data){
				  Node.grade = data.grade;
				  Node.isbottom = data.isbottom;		  
				  Node.parentcategoryid = data.parentcategoryid;
				  Node.cid = data.cid;
				};
				treeView.onSelect = function(Node){
				  page_view(Node.id, Node.grade, Node.isbottom, Node.parentid, Node.cid);
				};
											
				treeView.iniRoot('产品分类');
			});

</script>
</head>

<body>
      
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
	<form name="itemcategoryform" method="post" action="../../Dispatcher">  
    <input type="hidden" name="pagename" value="itemcategorytree">
    <input type="hidden" name="actionname">
       
    <input type="hidden" name="categoryid">
    <input type="hidden" name="isbottom">
    <input type="hidden" name="grade">
    <input type="hidden" name="parentcategoryid">
    <input type="hidden" name="cid">
    <input type="hidden" name="categoryorgid" value="<%=JspHelper.filterNull( nCurOrgId )%>">
    
    <input type="hidden" name="transferorgid" value='<%=JspHelper.filterNull((request.getParameter("transferorgid")==null)?"":(request.getParameter("transferorgid")))%>'>
    <input type="hidden" name="buyerid" value='<%=JspHelper.filterNull((request.getParameter("buyerid")==null)?"":(request.getParameter("buyerid")))%>'>
    <input type=hidden name="sellerid" value='<%=JspHelper.filterNull((request.getParameter("sellerid")==null)?"":(request.getParameter("sellerid")))%>'>
    <input type=hidden name="showtop20" value='<%=JspHelper.filterNull((request.getParameter("showtop20")==null)?"":(request.getParameter("showtop20")))%>'>
    <input type="hidden" name="ispoitem" value='<%=JspHelper.filterNull((request.getParameter("ispoitem")==null)?"":(request.getParameter("ispoitem")))%>'> 
    <input type="hidden" name="itemcode" value='<%=JspHelper.filterNull((request.getParameter("itemcode")==null)?"":(request.getParameter("itemcode")))%>'> 
    <input type="hidden" name="deptid" value='<%=JspHelper.filterNull((request.getParameter("deptid")==null)?"":(request.getParameter("deptid")))%>'> 
    
    <input type="hidden" name="orgid" value='<%=JspHelper.filterNull((request.getParameter("orgid")==null)?( ((Integer)userInfo.get("orgid")).toString()):(request.getParameter("orgid")))%>'>
    
       
  	<tr> 
    <td valign="top"> 
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
      </table>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center" height="92%">
        <tr> 
          <td colspan="-1" class="deepblue-left"><img src="../../images/<%= strLanguageCode %>/quote.gif" width="16" height="11"> 
            <%= label.getLabelName("L_ProductCategory") + label.getLabelName("L_Colon") %></td>
        </tr>
        <tr> 
          <td cellspacing="0" width="100%"> 
          <div id=div2 style="OVERFLOW: scroll; WIDTH: 184px; HEIGHT: 465px">
          <div id="treeView1"></div>	
           </td>
        </tr>
        <tr> 
          <td class="td-listrom">&nbsp;</td>
        </tr>
      </table>                               
  
      <table border="0" cellspacing="1" width="100%">
        <tr> 
          <td class="td_center">
          	<%--<a onclick=""><custom:button type="1" label="L_Search" imgsrc="search.gif" border="0" style="width:60"/></a>--%>
          	<a onclick="page_sum('all')"><custom:button type="1" label="L_ViewAll" imgsrc="ViewAll.gif" border="0" style="width:60"/></a>
        	<script language="javascript">
          	    var strOpenerLocation=parent.opener.location+"";
          	    strOpenerLocation=strOpenerLocation.toLowerCase();
          	    <%--[SCRIPT]  alert(strOpenerLocation);  [SCRIPT]--%>
          	    if(strOpenerLocation.indexOf("newsalesorderdetail")>0 || strOpenerLocation.indexOf("salesorderdetailsummary")>0 || !isEmpty(document.itemcategoryform.showtop20.value))
          	        document.write("<a onclick=\"page_sum('top20')\">"+'<custom:button type="1" label="L_Topp" imgsrc="topp.gif" border="0" style="width:60"/>'+"</a>");
          	</script>
          	</td>
        </tr>
      </table>
    </td>
  </tr>
</form>
</table>
    </body>
<script language="JavaScript">  
  var ht = document.body.clientHeight - 80;
  if(ht < 0 )
    ht = 0;
  div2.style.height= ht;
</script>
 <SCRIPT language=JavaScript1.2>
    initIt(itemcategoryform,'../../images/<%= strLanguageCode %>/');
    <%if(request.getParameter("selectopt")!=null){%>
    page_sum('<%=JspHelper.filterNull(request.getParameter("selectopt"))%>');
    <%}else{%>
    page_sum('all');
    <%}%>
    div2.style.display="block";
    </SCRIPT>   
    
</html>
